import { createRouter, createWebHistory } from 'vue-router';
import Index from '../views/Index.vue';
import BusinessList from '../views/BusinessList.vue';
import BusinessInfo from '../views/BusinessInfo.vue';
import Login from '../views/Login.vue';
import Orders from '../views/Orders.vue';
import UserAddress from '../views/UserAddress.vue';
import Payment from '../views/Payment.vue';
import OrderList from '../views/OrderList.vue';
import AddUserAddress from '../views/AddUserAddress.vue';
import EditUserAddress from '../views/EditUserAddress.vue';
import Register from '../views/Register.vue';
import MyPage from '../views/MyPage.vue';
import PaySuccess from '@/views/PaySuccess.vue';
import Setting from '../views/Setting.vue';
import EditUserName from '../views/EditUserName.vue';
import EditUserPassword from '../views/EditUserPassword.vue';
import SearchResults from '../views/SearchResults.vue';
import BeBusinessOwner from '@/views/BeBusinessOwner.vue';
import BusinessManagement from '@/views/BusinessManagement.vue';
import AddFood from '@/views/AddFood.vue';
import EditFood from '@/views/EditFood.vue';
import Find from '@/views/Find.vue';

// 创建 Vue 3 路由实例
const router = createRouter({
  history: createWebHistory(),
  routes: [
    {
      path: '/',
      name: 'Home',
      component: Index,
    },
    {
      path: '/index',
      name: 'Index',
      component: Index,
    },
    {
      path: '/businessList',
      name: 'BusinessList',
      component: BusinessList,
    },
    {
      path: '/businessInfo',
      name: 'BusinessInfo',
      component: BusinessInfo,
    },
    {
      path: '/login',
      name: 'Login',
      component: Login,
    },
    {
      path: '/orders',
      name: 'Orders',
      component: Orders,
    },
    {
      path: '/userAddress',
      name: 'UserAddress',
      component: UserAddress,
    },
    {
      path: '/payment',
      name: 'Payment',
      component: Payment,
    },
    {
      path: '/orderList',
      name: 'OrderList',
      component: OrderList,
    },
    {
      path: '/addUserAddress',
      name: 'AddUserAddress',
      component: AddUserAddress,
    },
    {
      path: '/editUserAddress',
      name: 'EditUserAddress',
      component: EditUserAddress, // 注意拼写
    },
    {
      path: '/register',
      name: 'Register',
      component: Register,
    },
    {
      path: '/myPage',
      name: 'MyPage',
      component: MyPage,
    },
    {
      path: '/paySuccess',
      name: 'PaySuccess',
      component: PaySuccess,
    },
    {
      path: '/setting',
      name: 'Setting',
      component: Setting,
    },
    {
      path: '/editUserName',
      name: 'EditUserName',
      component: EditUserName,
    },
    {
      path: '/editUserPassword',
      name: 'EditUserPassword',
      component: EditUserPassword,
    },
    {
      path: '/searchResults',
      name: 'SearchResults',
      component: SearchResults,
    },
    {
      path: '/beBusinessOwner',
      name: 'BeBusinessOwner',
      component: BeBusinessOwner,
    },
    {
      path: '/businessManagement',
      name: 'BusinessManagement',
      component: BusinessManagement,
    },
    {
      path: '/businessManagement',
      name: 'BusinessManagement',
      component: BusinessManagement,
    },
    {
      path: '/addFood',
      name: 'AddFood',
      component: AddFood,
    },
    {
      path: '/editFood',
      name: 'EditFood',
      component: EditFood,
    },
    {
      path: '/find',
      name: 'Find',
      component: Find,
    },
  ]
});


// 解决重复路由报异常问题（如果需要）
/*const originalPush = router.push;
router.push = function push(location, onResolve, onReject) {
  if (onResolve || onReject) return originalPush.call(this, location, onResolve, onReject);
  return originalPush.call(this, location).catch(err => err);
};*/

const originalPush = router.push;
router.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}
export default router;